<template>
  <div class="addrinfo box">
    <div class="backbox">
      <img
        src="@/assets/img/back.png"
        class="goback"
        @click="$router.replace('/addrlist')"
      />
    </div>
    <div class="addrinfocontainer">
      <div class="dkbtn" v-if="signDetail.status == 0" @click="toUpload">
        <img src="@/assets/img/dkbtn.png" />
      </div>
      <div class="dkbtn" v-else @click="toCheck">
        <img src="@/assets/img/dk_jindu_btn.png" />
      </div>
      <div class="infotopbox clmstart">
        <img :src="storeInfo.detail_top_url" class="headimg" />
        <div class="addrcont">
          <div class="namebox">
            <div class="ttitle">名称：</div>
            <div class="tcont">{{ storeInfo.name }}</div>
          </div>
          <div class="didianbox">
            <div class="ttitle">电话：</div>
            <div class="tcont">
              <a :href="'tel:' + storeInfo.mobile">{{ storeInfo.mobile }}</a>
            </div>
          </div>
          <div class="didianbox">
            <div class="ttitle">地点：</div>
            <div class="tcont">
              {{ storeInfo.address }}
              <img
                src="@/assets/img/mapto.png"
                @click="
                  mapTo(storeInfo.latitude, storeInfo.longitude, storeInfo.name)
                "
              />
            </div>
          </div>
        </div>
      </div>
      <!-- 推荐 -->
      <div class="tjlistcontainer clmstart">
        <!-- 保养 -->
        <div class="tjitem" v-if="storeInfo.tag.includes('保养')">
          <div class="title">
            <img src="@/assets/img/tj-by.png" />
          </div>
          <div class="tjinfobox clmstart">
            <div class="tjtext" v-show="storeInfo.care_recommend_content != ''">
              <p>{{ storeInfo.care_recommend_content }}</p>
            </div>
            <div
              class="tjimgbox clmstart"
              v-show="storeInfo.care_recommend_url.length > 0"
            >
              <div class="cardhead"></div>
              <div v-swiper:bySwiper="bySwiperOption">
                <div class="swiper-wrapper">
                  <div
                    class="swiper-slide"
                    v-for="bitem in storeInfo.care_recommend_url"
                    :key="bitem"
                  >
                    <img :src="bitem" />
                  </div>
                </div>
              </div>
            </div>
            <img
              src="@/assets/img/slidetip.png"
              class="slidetip"
              v-show="storeInfo.care_recommend_url.length > 0"
            />
          </div>
          <img src="@/assets/img/radius.png" class="boxradius" />
        </div>
        <!-- 餐饮 -->
        <div class="tjitem" v-if="storeInfo.tag.includes('餐饮')">
          <div class="title">
            <img src="@/assets/img/tj-cy.png" />
          </div>
          <div class="tjinfobox clmstart">
            <div class="tjtext" v-show="storeInfo.rest_recommend_content != ''">
              <p>{{ storeInfo.rest_recommend_content }}</p>
            </div>
            <div
              class="tjimgbox clmstart"
              v-show="storeInfo.rest_recommend_url.length > 0"
            >
              <div class="cardhead"></div>
              <div v-swiper:cySwiper="cySwiperOption">
                <div class="swiper-wrapper">
                  <div
                    class="swiper-slide"
                    v-for="citem in storeInfo.rest_recommend_url"
                    :key="citem"
                  >
                    <img :src="citem" />
                  </div>
                </div>
              </div>
            </div>
            <img
              src="@/assets/img/slidetip.png"
              class="slidetip"
              v-show="storeInfo.rest_recommend_url.length > 0"
            />
          </div>
          <img src="@/assets/img/radius.png" class="boxradius" />
        </div>
        <!-- 住宿 -->
        <div class="tjitem" v-if="storeInfo.tag.includes('住宿')">
          <div class="title">
            <img src="@/assets/img/tj-zs.png" />
          </div>
          <div class="tjinfobox clmstart">
            <div class="tjtext" v-show="storeInfo.stay_recommend_content != ''">
              <p>{{ storeInfo.stay_recommend_content }}</p>
            </div>
            <div
              class="tjimgbox clmstart"
              v-show="storeInfo.stay_recommend_url.length > 0"
            >
              <div class="cardhead"></div>
              <div v-swiper:zsSwiper="zsSwiperOption">
                <div class="swiper-wrapper">
                  <div
                    class="swiper-slide"
                    v-for="zitem in storeInfo.stay_recommend_url"
                    :key="zitem"
                  >
                    <img :src="zitem" />
                  </div>
                </div>
              </div>
            </div>
            <img
              src="@/assets/img/slidetip.png"
              class="slidetip"
              v-show="storeInfo.stay_recommend_url.length > 0"
            />
          </div>
          <img src="@/assets/img/radius.png" class="boxradius" />
        </div>
        <!-- 其他 -->
        <div class="tjitem" v-if="storeInfo.other_service_content != ''">
          <div class="title">
            <img src="@/assets/img/tj-qt.png" />
          </div>
          <div
            class="tjinfobox clmstart"
            v-show="storeInfo.other_service_content != ''"
          >
            <div class="tjtext">
              <p>
                {{ storeInfo.other_service_content }}
              </p>
            </div>
            <div
              class="tjimgbox clmstart"
              v-show="storeInfo.other_service_url.length > 0"
            >
              <div class="cardhead"></div>
              <div v-swiper:qtSwiper="qtSwiperOption">
                <div class="swiper-wrapper">
                  <div
                    class="swiper-slide"
                    v-for="qitem in storeInfo.other_service_url"
                    :key="qitem"
                  >
                    <img :src="qitem" />
                  </div>
                </div>
              </div>
            </div>
            <img
              src="@/assets/img/slidetip.png"
              class="slidetip"
              v-show="storeInfo.other_service_url.length > 0"
            />
          </div>
          <img src="@/assets/img/radius.png" class="boxradius" />
        </div>
        <!-- 救援服务 -->
        <div class="tjitem jybox" v-if="storeInfo.help_content != ''">
          <div class="title">
            <img src="@/assets/img/tj-jy.png" />
          </div>
          <div class="tjinfobox clmstart">
            <div class="tjtext">
              <p>{{ storeInfo.help_content }}</p>
            </div>
          </div>
          <img src="@/assets/img/radius.png" class="boxradius" />
        </div>
      </div>
    </div>
    <!-- 审核中 -->
    <Review v-show="reviewflag" @close="reviewflag = false" />
    <!-- 审核失败  -->
    <Fail v-show="failflag" @close="failflag = false" />
    <!-- 审核通过，显示奖品信息 -->
    <!-- 邮寄-填写收货地址 -->
    <Online
      :jpname="signDetail.prize"
      :jpimg="require(`@/assets/img/jp/g${signDetail.prizeId}.png`)"
      :wid="signDetail.wid"
      @closeOnline="OnlineSubCallBack"
      v-if="online_no_write_flag"
    />
    <!-- 邮寄-已填写和话费 -->
    <Gift
      :jpname="signDetail.prize"
      :jpimg="require(`@/assets/img/jp/g${signDetail.prizeId}.png`)"
      :tipflag="tipflag"
      v-if="online_is_write_flag"
    />
    <!-- 门店领取-需要填写摩托车编号 -->
    <Underline
      :jpname="signDetail.prize"
      :jpimg="require(`@/assets/img/jp/g${signDetail.prizeId}.png`)"
      :wid="signDetail.wid"
      @subCall="underlineSubCallBack"
      v-if="underline_no_write_flag"
    />
    <!-- 门店领取-不需要填写摩托车编号 -->
    <HxQrcode :qrcode="signDetail.qrcode" v-if="underline_is_write_flag" />
    <!-- 积分 -->
    <Jifen :jpname="signDetail.prize + ''" v-if="jifenflag" />
  </div>
</template>
<script>
import Review from "@/components/Review.vue";
import Fail from "@/components/Fail.vue";
import Online from "@/components/Online.vue";
import Gift from "@/components/Gift.vue";
import Underline from "@/components/Underline.vue";
import HxQrcode from "@/components/HxQrcode.vue";
import Jifen from "@/components/Jifen.vue";
import { Toast } from "vant";
import wx from "weixin-js-sdk";
export default {
  data() {
    let that = this;
    return {
      storeInfo: {}, //门店详情
      bySwiperOption: {
        on: {
          init: function () {
            that.$swiperAnimateCache(this); //隐藏动画元素
            that.$swiperAnimate(this); //初始化完成开始动画
          },
          slideChange: function () {
            that.$swiperAnimate(this); //每个slide切换结束时也运行当前slide动画
            //that.slides.eq(this.activeIndex).find('.ani').removeClass('ani'); 动画只展现一次，去除ani类名
          },
          slideChangeTransitionEnd: function () {
            // this.activeIndex 是索引index，这个用this才可以获取到
            // console.log(this.activeIndex);
          },
        },
      },
      cySwiperOption: {},
      zsSwiperOption: {},
      qtSwiperOption: {},
      distance: 0, //打卡距离
      signDetail: {
        // status: "", // 打卡状态 0代表未打卡，1代表审核中，2代表审核通过，-1代表审核失败
        // exch_method: 1, // 1代表邮寄产品，2代表门店领取，3代表积分，4代表话费
        // wid: 1, // 中奖记录id
        // prize: "", // 奖品名称
        // prizeId: "", // 奖品ID
        // isNeedWriteMotorCode: "", // exch_method为2 是否需要填写摩托车编号 1:需要填 0：不需要填
        // qrcode: "", // 核销二维码 isNeedWriteMotorCode为0时
        // isNeedWriteReceiver: 1, // exch_method为1 1：需要填 0：不需要填
        // receiver: "", // 收件人
        // mobile: "", // 收件人手机号
        // motor_code: "", // 摩托车编号
        // address: "", // 收件人地址
      },
      reviewflag: false, // 审核中
      failflag: false, // 审核失败
      online_no_write_flag: false, // 邮寄 未填写地址
      online_is_write_flag: false, // 邮寄 已填写地址
      underline_no_write_flag: false, // 门店领取 需要填写摩托车编号
      underline_is_write_flag: false, // 门店领取 不需要填写摩托车编号
      jifenflag: false, // 积分
      tipflag: false,
    };
  },
  created() {
    let id = this.$route.params.id;
    this.queryStoreInfo(id);
  },
  mounted() {
    if (this.storeInfo.tag.includes("保养")) {
      this.bySwiper.slideTo(0, 1000, false);
    }
    if (this.storeInfo.tag.includes("餐饮")) {
      this.cySwiper.slideTo(0, 1000, false);
    }
    if (this.storeInfo.tag.includes("住宿")) {
      this.zsSwiper.slideTo(0, 1000, false);
    }
    if (this.storeInfo.other_service_url.length > 0) {
      this.qtSwiper.slideTo(0, 1000, false);
    }
  },
  methods: {
    //查询门店详情
    queryStoreInfo(id) {
      this.$http
        .post("/getCheckInStoreDetailById", {
          id,
          latitude: window.localStorage.getItem("latitude"),
          longitude: window.localStorage.getItem("longitude"),
        })
        .then((res) => {
          // console.log(res);
          if (res.data.code == 200) {
            let rst = res.data.data;
            this.storeInfo = rst.info;
            this.distance = rst.distance;
            this.signDetail = rst.signDetail;
          } else {
            Toast(res.data.msg);
          }
        });
    },
    // //打开携程
    // xiechengTo(url) {
    //   window.open(url, "_blank");
    // },
    //打开地图
    mapTo(latitude, longitude, name) {
      var url = encodeURIComponent(window.location.href.split("#")[0]);
      this.$http
        .post("https://www.mahelei.com/index.php/Gm/Wechat/share", { url })
        .then((res) => {
          let data = res.data;
          wx.config({
            debug: true,
            appId: data.appId,
            timestamp: data.timestamp,
            nonceStr: data.nonceStr,
            signature: data.signature,
            jsApiList: ["checkJsApi", "openLocation"],
            success(res) {
              //   Toast(res);
            },
          });
        });
      wx.ready(() => {
        wx.checkJsApi({
          jsApiList: ["openLocation"],
          success: (rest) => {
            //打开指定位置
            wx.openLocation({
              latitude: latitude, // 纬度，浮点数，范围为90 ~ -90
              longitude: longitude, // 经度，浮点数，范围为180 ~ -180。
              name: name, // 位置名
              address: "", // 地址详情说明
              scale: 18, // 地图缩放级别,整型值,范围从1~28。默认为最大
              infoUrl: "", // 在查看位置界面底部显示的超链接,可点击跳转
            });
          },
        });
      });
    },
    //立即打卡
    toUpload() {
      if (this.distance > 1000) {
        Toast("超出打卡范围！");
        return;
      }
      this.$router.replace({
        name: "upload",
        params: {
          location_id: this.storeInfo.id,
          latitude: window.localStorage.getItem("latitude"),
          longitude: window.localStorage.getItem("longitude"),
          type: "1",
          name: this.storeInfo.name,
        },
      });
    },
    // 查看打卡进度
    toCheck() {
      switch (this.signDetail.status) {
        case "1":
          // 审核中
          if (this.signDetail.exch_method == "1") {
            // 邮寄产品
            if (this.signDetail.isNeedWriteReceiver == "1") {
              // 未需要填写
              this.online_no_write_flag = true;
            } else {
              // 已填写 审核中
              this.reviewflag = true;
            }
          } else if (this.signDetail.exch_method == "2") {
            // 门店领取
            if (this.signDetail.isNeedWriteMotorCode == "1") {
              // 未填写摩托车编号
              this.underline_no_write_flag = true;
            } else {
              // 已填写摩托车编号 审核中
              this.reviewflag = true;
            }
          } else {
            this.reviewflag = true;
          }
          break;
        case "2":
          // 审核通过
          // 1代表邮寄产品，2代表门店领取，3代表积分，4代表话费
          if (this.signDetail.exch_method == "1") {
            // 邮寄产品
            if (this.signDetail.isNeedWriteReceiver == "1") {
              // 未填写
              this.online_no_write_flag = true;
            } else {
              // 已填写
              this.tipflag = true;
              this.online_is_write_flag = true;
            }
          } else if (this.signDetail.exch_method == "2") {
            // 门店领取
            if (this.signDetail.isNeedWriteMotorCode == "1") {
              // 未填写摩托车编号
              this.underline_no_write_flag = true;
            } else {
              // 已填写摩托车编号
              this.underline_is_write_flag = true;
            }
          } else if (this.signDetail.exch_method == "3") {
            // 积分
            this.jifenflag = true;
          } else if (this.signDetail.exch_method == "4") {
            // 话费
            this.tipflag = false;
            this.online_is_write_flag = true;
          }
          break;
        case "-1":
          // 审核失败
          this.failflag = true;
          break;
        default:
          break;
      }
    },
    //  邮寄信息 提交成功
    OnlineSubCallBack() {
      this.online_no_write_flag = false;
      if (this.signDetail.status == "1") {
        this.reviewflag = true;
      } else if (this.signDetail.status == "2") {
        this.tipflag = true;
        this.online_is_write_flag = true;
      }
      let id = this.$route.params.id;
      this.queryStoreInfo(id);
    },
    // 提交成功-线下领取 摩托车编号
    underlineSubCallBack(qrcode) {
      this.underline_no_write_flag = false;
      if (this.signDetail.status == "1") {
        this.reviewflag = true;
      } else if (this.signDetail.status == "2") {
        this.signDetail.qrcode = qrcode;
        this.underline_is_write_flag = true;
      }
    },
  },
  components: {
    Review,
    Fail,
    Online,
    Gift,
    Underline,
    HxQrcode,
    Jifen,
  },
};
</script>
<style lang="less" scoped>
.addrinfo {
  overflow-y: scroll;
  .backbox {
    position: absolute;
    z-index: 2;
  }
  .addrinfocontainer {
    position: relative;
    width: 100%;
    height: auto;
    min-height: 100%;
    background: url("@/assets/img/bg.jpg") repeat-y;
    background-size: cover;
    .dkbtn {
      position: fixed;
      right: 1rem;
      top: 28rem;
      width: 179px;
      height: 179px;
      overflow: hidden;
      z-index: 9;
      img {
        display: block;
        width: 100%;
      }
    }
    .infotopbox {
      position: relative;
      width: 100%;
      height: auto;
      .headimg {
        width: 100%;
        height: 540px;
        object-fit: cover;
        vertical-align: middle;
      }
      .addrcont {
        width: 100%;
        height: 362px;
        margin-top: -5rem;
        background: url("@/assets/img/infotopbox.png") no-repeat;
        background-size: 100% 100%;
        font-size: 1.8rem;
        div {
          text-align: left;
        }
        .namebox,
        .didianbox {
          width: 93%;
          margin: 0 auto;
          display: flex;
          justify-content: flex-start;
          align-items: flex-start;
          div {
            padding: 0.5rem 0;
          }
          .ttitle {
            width: 100px;
            font-family: "AlibabaPuHuiTi-2-85-Bold";
          }
          .tcont {
            width: calc(100% - 100px);
            a {
              text-decoration: none;
            }
          }
        }
        .namebox {
          padding-top: 2rem;
        }
        .didianbox {
          div {
            img {
              margin: 1rem 0;
            }
          }
        }
      }
    }
    // 推荐列表
    .tjlistcontainer {
      width: 100%;
      padding-bottom: 6rem;
      .tjitem {
        position: relative;
        width: 729px;
        height: auto;
        background: url("@/assets/img/tjbg.png") no-repeat top center;
        background-size: contain;
        margin: 2rem 0 1rem 21px;
        .boxradius {
          position: absolute;
          right: 1.8rem;
          top: 6.6rem;
        }
        .title {
          position: relative;
          width: 50%;
          height: 95px;
          margin-left: 2rem;
          img {
            padding-top: 2rem;
          }
        }
        .tjinfobox {
          width: 97.5%;
          height: auto;
          min-height: 708px;
          background-color: #fbce07;
          border: 2px solid #f39500;
          box-sizing: border-box;
          border-top: none;
          border-radius: 1.5rem;
          .tjtext,
          .tjimgbox {
            width: 92%;
            border-radius: 1rem;
          }
          .tjtext {
            margin-top: 2rem;
            min-height: 240px;
            background: #ffffff;
            p {
              font-size: 1.5rem;
              color: #000000;
              padding: 1.5rem;
            }
          }
          .tjimgbox {
            position: relative;
            height: 353px;
            border: 5px solid #000000;
            box-sizing: border-box;
            margin-top: 2.5rem;
            .cardhead {
              position: absolute;
              top: -12px;
              width: 140px;
              height: 12px;
              border-radius: 2rem;
              background: #000000;
            }
            .swiper-container {
              position: relative;
              width: 100%;
              height: 100%;
              margin: 0;
              padding: 0;
              border-radius: 1rem;
              overflow: hidden;
              .swiper-slide {
                display: flex;
                flex-flow: column nowrap;
                justify-content: center;
                align-items: center;
                font-size: 2rem;
                img {
                  width: 100%;
                  height: 100%;
                  object-fit: cover;
                }
              }
            }
          }
          .slidetip {
            margin: 1.5rem auto;
          }
        }
      }
      .jybox {
        .tjinfobox {
          .tjtext {
            margin-bottom: 3rem;
          }
        }
      }
    }
  }
}
</style>
